package top.ooyyh.bytheway.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.ooyyh.bytheway.annotation.NeedAuthorization;
import top.ooyyh.bytheway.mapper.UserMapper;
import top.ooyyh.bytheway.model.request.CreateUserRequest;
import top.ooyyh.bytheway.model.request.LoginRequest;
import top.ooyyh.bytheway.model.request.RegisterRequest;
import top.ooyyh.bytheway.service.UserService;
import top.ooyyh.bytheway.utils.Result;
@RestController
@CrossOrigin
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserMapper userMapper;
    @Autowired
    UserService userService;
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    @ResponseBody
    public Result login(@RequestBody LoginRequest loginRequest) {
        return userService.login(loginRequest);
    }
    @GetMapping("/loginWithOutPass")
    @ResponseBody
    public Result loginWithOutPass(@RequestHeader("Authorization") String token) {
        return userService.loginWithOutPass(token);
    }
    @RequestMapping(value = "/register",method = RequestMethod.POST)
    @ResponseBody
    public Result register(@RequestBody RegisterRequest registerRequest) {
        return userService.register(registerRequest);
    }
    @RequestMapping(value = "/registerByEmail",method = RequestMethod.POST)
    @ResponseBody
    public Result registerByEmail(@RequestBody RegisterRequest registerRequest) {
        return userService.registerByEmail(registerRequest);
    }
    @RequestMapping(value = "/getUserMenu" , method = RequestMethod.GET)
    @ResponseBody
    public Result getUserMenu(@RequestHeader("Authorization") String token) {
        return userService.getUserMenu(token);
    }
    @RequestMapping(value = "/tunnelTest",method = RequestMethod.GET)
    @ResponseBody
    public Result tunnelTest() {
        return Result.success("fantastic");
    }
    @NeedAuthorization
    @RequestMapping(value = "/createUser",method = RequestMethod.POST)
    @ResponseBody
    public Result createUser(@RequestBody CreateUserRequest user){
        return userService.createUser(user);
    }
    @NeedAuthorization
    @RequestMapping(value = "/permissionTest",method = RequestMethod.GET)
    @ResponseBody
    public String testAOP(@RequestHeader("Authorization") String token) {
        return "0";
    }
    @NeedAuthorization
    @RequestMapping(value = "/getAllRolePower",method = RequestMethod.GET)
    @ResponseBody
    public Result getAllRole() {
        return userService.getAllRolePower();
    }

}
